<template>
  <div class="app-container">
    <el-form
      ref="listFilterRef"
      :model="list.filter"
      inline
      class="list-filter"
    >
      <el-form-item prop="name">
        <el-input v-model="list.filter.name" placeholder="攻略名称">
          <i slot="prefix" class="el-input__icon el-icon-search" />
        </el-input>
      </el-form-item>
      <el-form-item prop="placeId">
        <DestinationSelect
          v-model="list.filter.placeId"
          filterType="地区|景区|场馆"
          placeholder="所属地点"
        />
      </el-form-item>
      <el-form-item prop="status">
        <Status v-model="list.filter.status" />
      </el-form-item>
      <el-form-item>
        <el-button @click="reset">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <div class="table-operation">
      <AuthButton @click="c" name="新增" />
      <el-pagination
        v-bind="elPaginationProps"
        :total="list.total"
        :currentPage.sync="list.filter.pageNo"
        :pageSize.sync="list.filter.pageSize"
      />
    </div>

    <el-table v-loading="list.loading" :data="list.data" v-bind="tableProp">
      <el-table-column label="攻略名称" align="center" prop="name" />
      <el-table-column label="所属地点" align="center" prop="placeName" />
      <el-table-column label="启用状态" width="80" align="center">
        <template slot-scope="{ row: { id, status } }">
          <KiPopSwitch
            v-bind="popSwitchProps(status)"
            @change="updateStatus({ id, status: status ^ 1 })"
          />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding">
        <template slot-scope="{ row }">
          <auth-button @click="u({ id: row.id })" name="编辑" />
          <auth-button @click="d({ id: row.id })" name="删除" />
        </template>
      </el-table-column>
    </el-table>

    <KiFormDialog
      :show.sync="form.show"
      :title="formTitle"
      v-model="form.data"
      :submit="submitForm"
      :readonly="form.status === 'r'"
      ref="formRef"
      :loading="form.loading"
    >
      <template #el-form>
        <el-form-item label="所属地点" prop="places" verify>
          <DestinationSelect
            v-model="form.data.places"
            filterType="地区|景区|场馆"
            multiple
            placeholder="搜索 地区 | 景区 | 场馆"
            v-if="form.show"
          />
        </el-form-item>
        <el-form-item label="攻略名称" prop="name" verify>
          <el-input
            v-model="form.data.name"
            placeholder="请输入攻略名称"
            maxlength="30"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="发布人" prop="applyUserName" verify>
          <el-input v-model="form.data.applyUserName" maxlength="10" show-word-limit clearable/>
        </el-form-item>
        <el-form-item label="封面图片" prop="indexImg" verify>
          <Imgpond
            v-model="form.data.indexImg"
            aspectRatio="346/358"
            value-type="array"
            :count="4"
          />
        </el-form-item>
        <el-form-item label="攻略图集" prop="img" verify>
          <Imgpond
            v-model="form.data.img"
            value-type="array"
            :count="9"
            aspectRatio="750/576"
          />
        </el-form-item>
        <el-form-item label="详细介绍" prop="detailProfile" verify>
          <MiniMCE v-model="form.data.detailProfile" :disabled="form.status === 'r'"/>
        </el-form-item>
      </template>
    </KiFormDialog>
  </div>
</template>

<script>
import pageMixin from '@/utils/pageMixin'
import useAdmateAdapter from '@/utils/useAdmateAdapter'
import DestinationSelect from '@/components/DestinationSelect'

export default {
  mixins: [pageMixin],
  components: { DestinationSelect },
  setup: () =>
    useAdmateAdapter({
      urlPrefix: 'one-travel-api/strategy',
      list: {
        filter: {
          placeId: ''
        }
      }
    }),
  methods: {}
}
</script>

<style lang="scss" scoped></style>
